package com.gitee.minimalismstyle.fresh.common.data.beetl.model

import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer
import com.gitee.minimalismstyle.fresh.common.data.beetl.annotation.*
import io.swagger.annotations.ApiModelProperty
import org.beetl.sql.annotation.entity.AssignID
import org.beetl.sql.annotation.entity.LogicDelete
import org.beetl.sql.annotation.entity.UpdateIgnore
import org.beetl.sql.annotation.entity.Version
import java.time.LocalDateTime
import java.io.Serializable

abstract class Model<ID>: Serializable {

    /**
     * 主键
     */
    @AssignID
    @ApiModelProperty(value = "主键")
    open var id: ID? = null

    /**
     * 创建人
     */
    @CreatedBy
    @ApiModelProperty(value = "创建人")
    @UpdateIgnore
    open var createdBy: Long? = null

    /**
     * 创建时间
     */
    @ApiModelProperty(value = "创建时间")
    @CreatedDate
    @UpdateIgnore
    @JsonSerialize(using = LocalDateTimeSerializer::class)
    @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
    open var createdDate: LocalDateTime? = null

    /**
     * 最后更新人
     */
    @LastModifiedBy
    @ApiModelProperty(value = "最后更新人")
    open var lastModifiedBy: Long? = null

    /**
     * 最后更新时间
     */
    @LastModifiedDate
    @ApiModelProperty(value = "最后更新时间")
    @JsonSerialize(using = LocalDateTimeSerializer::class)
    @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
    open var lastModifiedDate: LocalDateTime? = null

    @Version
    @ApiModelProperty(value = "版本号")
    open var version: Int = 0

    /**
     * 逻辑删除（0：已删除，1：未删除）
     */
    @ApiModelProperty(value = "逻辑删除（0：已删除，1：未删除）")
    @LogicDelete
    open var delFlag: Int = 1

    /**
     * 租户ID
     */
    @ApiModelProperty(value = "租户ID")
    @TenantId
    @UpdateIgnore
    open var tenantId: Long? = null

    fun reset(){
        this.id = null
        this.createdBy = null
        this.createdDate = null
        this.lastModifiedBy = null
        this.lastModifiedDate = null
        this.version = 0
        this.delFlag = 1
        this.tenantId = null
    }
}